from google.appengine.api import memcache
import pydelicious

def get_data(key, f):
    data = memcache.get(key)
    if data is None:
        data = f()
        if not data:
            memcache.add(key, [], 60*10)
        else:
            memcache.add(key, data, 60*60*24)
    return data

def get_urlposts(url):
    key = "urlposts:" + url
    return get_data(key, lambda:pydelicious.get_urlposts(url))

def getrss(user, tag):
    key = "getrss:" + user + "/" + tag
    return get_data(key, lambda:pydelicious.getrss(user=user, tag=tag))
